'use strict'

var http=require('http')

let html=` 
    <!DOCTYPE html>
    <html>
        <head>
            <title>First Server</title>
        </head>
        <body>
            <div>Node.js in service.</div>
        </body>
    </html>
    `
var server=http.createServer();
server.listen(1214);
server.on('request',(request,response)=>{
    console.log(request.url);
    if(request.url=='/x/y/z'){
        var bufferStr='';
        request.on('data',function(chunk){
            bufferStr+=chunk.toString("utf-8");
        });
        request.on("end",()=>{
            response.setHeader('content-type','text/plain;charset=utf-8');
            response.end(bufferStr);
        })
    }else if(request.url=='/x/y'){
        response.setHeader('content-type','text/html;charset=utf-8');
        response.end(html);
    }else if(request.url=='/x'){
        response.setHeader('content-type','text/plain;charset=utf-8');
        response.end('--ok--');
    }else{
        response.statusCode=404;
        response.end('page not found');
    }
})